﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.Routing;

namespace LunchListControls
{
	public static class Server
	{
		public static MvcHtmlString AjaxBooleanFor<TModel, TValue>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression, string htmlInput, string actionName, string controllerName, object htmlAttributes = null)
		{
			ModelMetadata data = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);
			string propertyName = data.PropertyName;
			TagBuilder span = new TagBuilder("span");
			span.Attributes.Add("name", propertyName);
			span.Attributes.Add("data-something", "something");

			if (htmlAttributes != null)
			{
				RouteValueDictionary attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
				span.MergeAttributes(attributes);
			}

			return new MvcHtmlString(span.ToString());
		}
    }
}
